package edu.upn.sigemfi.rec.beans;

//import edu.upn.sigemfi.rec.bc.CreditoDelegate;
import edu.upn.sigemfi.rec.bc.CreditoDelegate;
import edu.upn.sigemfi.rec.be.Credito;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Diego
 */
public class CreditoController {

    private CreditoDelegate delegado;
    private Credito credito;
    private String selectedItem;

    public String getSelectedItem() {
        return selectedItem;
    }

    public void setSelectedItem(String selectedItem) {
        this.selectedItem = selectedItem;
    }

    public Credito getCredito() {
        return credito;
    }

    public void setCredito(Credito credito) {
        this.credito = credito;
    }

    public CreditoController() {
        delegado = new CreditoDelegate();
    }

    public List<Credito> getCreditos() throws Exception {
        try {
            return delegado.listar();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    public List<Credito> getCreditosVigentes() throws Exception {
        try {
            return delegado.listarVigentes();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    public List<Credito> getCreditosVencidos() throws Exception {
        try {
            return delegado.listarVencidos();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    public List<Credito> getCreditosRefinanciados() throws Exception {
        try {
            return delegado.listarRefinanciados();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    public List<Credito> getCreditosPrejudicial() throws Exception {
        try {
            return delegado.listarPrejudiciales();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    public List<Credito> getCreditosJudicial() throws Exception {
        try {
            return delegado.listarJudiciales();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    public List<Credito> getCreditosCastigados() throws Exception {
        try {
            return delegado.listarCastigados();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    public String nuevo() {
        credito = new Credito();
        return "nuevo";
    }

    public List<Credito> getCreditosCartera() throws Exception {
        try {
            List<Credito> vigentes = new ArrayList<Credito>();
            List<Credito> todos = delegado.listar();
            for (Credito c : todos) {
                if (c.getFidRecCartera().getIdCartera() == Integer.parseInt(selectedItem)) {
                    vigentes.add(c);
                }
            }
            return vigentes;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
    public String setSelect(){
        return "";
    }
}
